﻿using StartsEAS_API.Model.Models;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace StartsEAS_API.DAL.RegionalD
{
    public class RegionalDAL
    {
        private readonly StarsEASContext _context;
        public RegionalDAL(StarsEASContext context)
        {
            _context = context;
        }

        public IEnumerable<Province> GetAllProvince() {
            StarsEASContext _context = new StarsEASContext();
            IEnumerable<Province> provinces = _context.Provinces.ToList();
            return provinces;
        }

        public Province GetProvincByProvinceCode(int ProvinceCode) {
            StarsEASContext _context = new StarsEASContext();
            Province province = _context.Provinces.FirstOrDefault(p => p.ProvinceCode == ProvinceCode);
            if (province == null) return null;
            return province;
        }

        public Province GetProvincByProvinceName(string ProvinceName)
        {
            StarsEASContext _context = new StarsEASContext();
            Province province = _context.Provinces.FirstOrDefault(p => p.ProvinceName == ProvinceName);
            if (province == null) return null;
            return province;
        }

        public IEnumerable<City> GetCity(int ProvinceCode)
        {
            StarsEASContext _context = new StarsEASContext();
            IEnumerable<City> citys = _context.Cities.Where(c=>c.ProvinceCode==ProvinceCode).ToList();
            return citys;
        }

        public City GetCityByCityCode(int CityCode)
        {
            StarsEASContext _context = new StarsEASContext();
            City city = _context.Cities.FirstOrDefault(c => c.CityCode == CityCode);
            if (city == null) return null;
            return city;
        }

        public City GetCityByCityName(string CityName)
        {
            StarsEASContext _context = new StarsEASContext();
            City city = _context.Cities.FirstOrDefault(c => c.CityName == CityName);
            if (city == null) return null;
            return city;
        }

        public IEnumerable<Area> GetArea(int CityCode)
        {
            StarsEASContext _context = new StarsEASContext();
            IEnumerable<Area> areas = _context.Areas.Where(c => c.CityCode == CityCode).ToList();
            return areas;
        }

        public Area GetAreaByAreaCode(int AreaCode)
        {
            StarsEASContext _context = new StarsEASContext();
            Area area = _context.Areas.FirstOrDefault(c => c.AreaCode == AreaCode);
            if (area == null) return null;
            return area;
        }

        public Area GetAreaByAreaName(string AreaName)
        {
            StarsEASContext _context = new StarsEASContext();
            Area area = _context.Areas.FirstOrDefault(c => c.AreaName == AreaName);
            if (area == null) return null;
            return area;
        }

    }
}
